/*
 * @Author: Turump 
 * @Date: 2021-05-11 15:17:22 
 * @Last Modified by: Turump
 * @Last Modified time: 2021-05-12 10:01:19
 */

import { TweenType } from "../../misc/TweenType";
import ActionBaseTask from "./ActionBaseTask";

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu("动作任务/改变ZIndex")
export default class ChangeZIndexTask extends ActionBaseTask {

    @property({ displayName: "动作带音效", override: true, visible: false })
    withAudio = false

    @property({ displayName: "任务支持暂停", override: true, visible: false })
    isPauseable = false;

    @property({ displayName: "动作执行时长", override: true, visible: false })
    actionDuration = 0.5;

    @property({ displayName: "完成发送事件", override: true, visible: false })
    isEmitDoneEvent = false;

    @property({ displayName: "缓动类型", type: cc.Enum(TweenType), override: true, visible: false })
    easeType: TweenType = TweenType.linear;

    @property({ displayName: "相对节点", type: cc.Node })
    relativeNode: cc.Node = null;

    @property({ displayName: "绝对值", visible() { return this.relativeNode == null } })
    absoluteValue = 0;

    @property({ displayName: "相对值", visible() { return this.relativeNode != null } })
    relativeValue = 0;

    getAction() {
        return cc.tween(this.node).call(() => {
            if (this.relativeNode) {
                this.node.setSiblingIndex(this.relativeNode.getSiblingIndex() + this.relativeValue);
                return;
            }
            this.node.zIndex = this.absoluteValue;
        })
    }
}
